package com.gggd.aopdemo.aop;

import com.gggd.aopdemo.vo.User;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @Description
 * @Author srx
 * @date 2021/12/24 18:21
 */
@Component
@Aspect
public class MyAop04 {
    @Pointcut("@annotation(com.gggd.aopdemo.anno.MyAnnotation)")
    private void myAop04Pointcut() {
    }


    @Around("myAop04Pointcut()")
    public Object myAop04(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("===================开始增强处理===================");

        //获取请求参数
        Object[] objects = joinPoint.getArgs();
        Integer uid = ((User) objects[0]).getUid();
        String name = ((User) objects[0]).getName();
        System.out.println("id1->>>>>>>>>>>>>>>>>>>>>>" + uid);
        System.out.println("name1->>>>>>>>>>>>>>>>>>>>>>" + name);

        // 修改入参
        User user = new User();
        user.setUid(1000);
        user.setName("张三");
        objects[0] = user;

        // 将修改后的参数传入
        return joinPoint.proceed(objects);
    }
}
